/*
 * @lc app=leetcode.cn id=1588 lang=javascript
 *
 * [1588] 所有奇数长度子数组的和
 */

// @lc code=start
/**
 * @param {number[]} arr
 * @return {number}
 */
var sumOddLengthSubarrays = function (arr) {
  let sum = 0;
  for (let len = 1; len <= arr.length; len += 2) {
    let init = 0;
    for (let k = 0; k < len; k++) {
      init += arr[k];
    }
    sum += init;
    let start = 0, end = len;
    while (end < arr.length) {
      init = init - arr[start++] + arr[end++];
      sum += init;
    }
  }
  return sum;
};
// @lc code=end

